import DefaultConfig from "./project.config/default.config";
import AdminConfig from "./project.config/admin.config";
import IndexConfig from "./project.config/index.config";
import H5Config from "./project.config/h5.config";

// 系统配置
const sysConfig: SysProps<SysConfigProp> = {
  default: DefaultConfig,
  admin: AdminConfig,
  index: IndexConfig,
  h5: H5Config
};

/**
 * 获取系统配置
 * @param {ImportMetaEnv["VITE_PROJECT"]} project - 项目
 * */
export const useSysConfig = (project?: ImportMetaEnv["VITE_PROJECT"]) => {
  // 当前项目
  project = project || import.meta.env.VITE_PROJECT;

  if (project && sysConfig[project]) {
    return sysConfig[project];
  }

  return sysConfig.default;
};

/**
 * 定义 sysConfig 的结构类型
 * */
export interface SysConfigProp {
  // 项目名
  project: keyof SysProps;
  // 项目基地址
  baseUrl: "/" | "/admin" | "index" | "h5" | string;
  // 项目启动端口
  port: 9000 | 9001 | 9002 | 9003 | number;
  // localstorage键名
  localKey?: {
    [key: string]: string;
  };
}
